package cn.wolfcode.shop.service.impl;

import cn.wolfcode.shop.domain.PropertyValue;
import cn.wolfcode.shop.domain.SkuPropertyValue;
import cn.wolfcode.shop.mapper.PropertyValueMapper;
import cn.wolfcode.shop.mapper.SkuPropertyValueMapper;
import cn.wolfcode.shop.service.IPropertyValuesService;
import cn.wolfcode.shop.service.ISkuPropertyValuesService;
import com.alibaba.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class SkuPropertyValuesServiceImpl implements ISkuPropertyValuesService {
    @Autowired
    private SkuPropertyValueMapper propertyValueMapper;


    @Override
    public void deleteById(Long id) {
        propertyValueMapper.deleteByPrimaryKey(id);
    }

    @Override
    public List<SkuPropertyValue> getValuesByPropertyId(Long propertyId) {
        List<SkuPropertyValue> propertyValues=propertyValueMapper.selectByPropertyId(propertyId);
        return propertyValues;
    }

    @Override
    public void inputValues(List<SkuPropertyValue> propertyValueList) {
        propertyValueList.forEach(propertyValue -> {
            if(propertyValue.getId()==null)
                propertyValueMapper.insert(propertyValue);
            else
                propertyValueMapper.updateByPrimaryKey(propertyValue);
        });
    }
}
